Fix some valgrind warnings/errors.
authoroliskoli <oliskoli>
Tue, 24 Jul 2007 08:51:26 +0000 (08:51 +0000)
committeroliskoli <oliskoli>
Tue, 24 Jul 2007 08:51:26 +0000 (08:51 +0000)
compegps.c
pathaway.c
pdbfile.c
pdbfile.h

index 0aa41ef409180d67325220ec0262d0bd40ee0505..a47400d8c98e63664bafabbf2d904c1e6313ce8c 100644 (file)
@@ -515,6 +515,7 @@ write_trkpt_cb(const waypoint *wpt)
                strftime(buff, sizeof(buff), "%d-%b-%y %H:%M:%S", &tm);
                strupper(buff);
        }
+       else strncpy(buff, "01-JAN-70 00:00:00", sizeof(buff));
        
        gbfprintf(fout, "T  A %.10f%c%c %.10f%c%c ",
                fabs(wpt->latitude), 0xBA, (wpt->latitude >= 0) ? 'N' : 'S',
index b1461ea17d058ae7849c44a11158213d95b12afe..ee3705760c452633cd05dea65d9338f6c6090da4 100644 (file)
@@ -60,6 +60,7 @@ typedef struct ppdb_appdata
 } ppdb_appdata_t;
 
 #define PPDB_APPINFO_SIZE sizeof(struct ppdb_appdata)
+static ppdb_appdata_t *appinfo;
 
 static char *opt_dbname = NULL;
 static char *opt_deficon = NULL;
@@ -535,6 +536,7 @@ static void ppdb_wr_init(const char *fname)
        file_out = pdb_create(fname, MYNAME);
        mkshort_handle = mkshort_new_handle();
        ct = 0;
+       appinfo = NULL;
        
        if (global_opts.synthesize_shortnames != 0)
        {
@@ -561,6 +563,7 @@ static void ppdb_wr_deinit(void)
        str_pool_deinit();
        xfree(fname_out);
        if (datefmt) xfree(datefmt);
+       if (appinfo) xfree(appinfo);
 }
 
 /*
@@ -651,12 +654,10 @@ static void ppdb_write_wpt(const waypoint *wpt)
  
 static void ppdb_write(void)
 {
-       ppdb_appdata_t *appinfo = NULL;
        
        if (opt_dbname)
            strncpy(file_out->name, opt_dbname, PDB_DBNAMELEN);
            
-       file_out->name[PDB_DBNAMELEN-1] = 0;
        file_out->attr = PDB_FLAG_BACKUP;
        file_out->ctime = file_out->mtime = current_time() + 2082844800U;
        file_out->creator = PPDB_MAGIC;
@@ -664,8 +665,7 @@ static void ppdb_write(void)
        
        if (global_opts.objective != wptdata)   /* Waypoint target do not need appinfo block */
        {
-           appinfo = xcalloc(PPDB_APPINFO_SIZE, 1);
-           
+           appinfo = xcalloc(1, sizeof(*appinfo));
            file_out->appinfo = (void *)appinfo;
            file_out->appinfo_len = PPDB_APPINFO_SIZE;
        }
@@ -693,8 +693,6 @@ static void ppdb_write(void)
                fatal(MYNAME ": Realtime positioning not supported.\n");
                break;
        }
-
-       if (appinfo != NULL) xfree(appinfo);
 }
 
 
index d9a95a974e3168b595c7bb4d89f822647f1bcf69..18f2c617362deda1b3ad42793065eb509ec1c5f0 100644 (file)
--- a/pdbfile.c
+++ b/pdbfile.c
@@ -72,9 +72,9 @@ pdb_load_data(pdbfile *fin)
        pdbrec_t *rec;
        
        /* load the header */
-       fin->name = xcalloc(1, 32 + 1);
-       gbfread(fin->name, 1, 32, fin->file);
-       
+       gbfread(fin->name, 1, PDB_DBNAMELEN, fin->file);
+       fin->name[PDB_DBNAMELEN] = '\0';
+
        fin->attr = gbfgetuint16(fin->file);
        fin->version = gbfgetuint16(fin->file);
        fin->ctime = gbfgetuint32(fin->file);
@@ -219,7 +219,6 @@ pdb_create(const char *filename, const char *module)
        pdbfile *res;
 
        res = xcalloc(1, sizeof(*res));
-       res->name = xmalloc(PDB_DBNAMELEN + 1);
        strncpy(res->name, "Palm/OS Database", PDB_DBNAMELEN);
        res->file = gbfopen_be(filename, "wb", module);;
        res->mode = 2;
@@ -305,9 +304,8 @@ pdb_flush(pdbfile *file)
        }
 
        len = strlen(file->name);
-       if (len > 32) len = 32;
        gbfwrite(file->name, 1, len, fout);
-       while (len++ < 32) gbfputc(0, fout);
+       while (len++ < PDB_DBNAMELEN) gbfputc(0, fout);
 
        gbfputuint16(file->attr, fout);
        gbfputuint16(file->version, fout);
@@ -337,10 +335,9 @@ pdb_flush(pdbfile *file)
                gbfwrite(file->appinfo, 1, file->appinfo_len, fout);
        }
 
-       rec = file->rec_list;
-       while (rec) {
-               gbfwrite(rec->data, 1, rec->size, fout);
-               rec = rec->next;
+       for (rec = file->rec_list; rec; rec = rec->next) {
+               if (rec->size > 0)
+                       gbfwrite(rec->data, 1, rec->size, fout);
        }
 }
 
@@ -366,7 +363,6 @@ pdb_close(pdbfile *file)
        gbfclose(file->file);
 
        if ((file->mode & 1) && file->appinfo) xfree(file->appinfo);
-       xfree(file->name);
        
        rec = file->rec_list;
        while (rec) {
index 4b288897694e54ccca6cd2973cf99f97e604dbd8..bcfc4cac8ac5322fb6bd16e16be50bd7b1afa5b0 100644 (file)
--- a/pdbfile.h
+++ b/pdbfile.h
@@ -51,7 +51,7 @@ typedef struct pdbrec_s {
 typedef struct {
        gbfile *file;
        char mode;              /* file-mode: 1 = read / 2 = write */
-       char *name;             /* database name */
+       char name[PDB_DBNAMELEN + 1];   /* database name */
        gbuint16 attr;          /* attributes */
        gbuint16 version;       /* version */
        time_t ctime;           /* creation time */